package com.southwind.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RocketMQMessageListener(consumerGroup = "order", topic = "myTopic")
@Slf4j
public class MessageService implements RocketMQListener<String> {

    @Autowired
    private  WebSocket webSocket;

    /**
     * 收到了MQ的消息
     */
    @Override
    public void onMessage(String message) {
        log.info("【RocketMQ】收到了消息：{}", message);
        // 使用webSocket发送消息
        webSocket.sendMessage(message);
    }
}
